<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Vue搜索歌曲</title>
    <script src="public/vue.js"></script>
    <style>
        /* 通用样式 */
        body {
            font-family: Arial, sans-serif;
            background-color: #f4f4f4;
            color: #333;
            margin: 0;
            padding: 0;
        }

        /* 容器样式 */
        .container {
            max-width: 600px;
            margin: 50px auto;
            padding: 20px;
            background-color: #fff;
            border-radius: 8px;
            box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
        }

        /* 输入框样式 */
        .search {
            width: 100%;
            padding: 10px;
            margin-bottom: 20px;
            font-size: 16px;
            border: 1px solid #ccc;
            border-radius: 4px;
            box-sizing: border-box;
            /* 保持宽度一致 */
        }

        .search:focus {
            outline: none;
            border-color: #007bff;
            box-shadow: 0 0 5px rgba(0, 123, 255, 0.5);
        }

        /* 列表样式 */
        ul {
            list-style: none;
            padding: 0;
            margin: 0;
        }

        li {
            padding: 10px;
            border-bottom: 1px solid #eee;
            font-size: 16px;
            color: #555;
            transition: background-color 0.3s;
        }

        li:last-child {
            border-bottom: none;
        }

        /* 鼠标悬停效果 */
        li:hover {
            background-color: #f9f9f9;
            cursor: pointer;
        }

        /* 奇偶行样式 */
        li:nth-child(odd) {
            background-color: #c9bfbf;
        }

        /* 活跃状态（可选） */
        li.active {
            background-color: #e6f7ff;
            color: #007bff;
        }
    </style>
</head>

<body>

    <div id="app">
        <h1>播放列表</h1>
        <input placeholder="请输入歌曲名自动搜索" type="text" class="search" v-model="searchItem">
        <ul>
            <li v-for="(song,index) in filteredPlayList"> 第{{index+1}}首歌曲: {{song}}</li>
        </ul>
    </div>

    <script>
        var app = new Vue({
            el: "#app",
            data: {
                playList: ["Bang Bang", "Only you", "下等马", "I want to konw"],
                searchItem: ""
            },
            computed: {
                // 注意写一个函数的正确姿势
                filteredPlayList() {
                    if (this.searchItem) {
                        return this.playList.filter((song) =>
                            song.toLowerCase().includes(this.searchItem.toLowerCase()))
                    } else {
                        return this.playList
                    }
                }
            }
        })
    </script>


</body>

</html>